2020-2021 Sunseeker Telemetry and Lighting System
cs_ex4_XTSourcesDCOInternal.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
66 //*****************************************************************************
67 #include "driverlib.h"
68 
69 //*****************************************************************************
70 //
71 //Desired Timeout for XT1 initialization
72 //
73 //*****************************************************************************
74 #define CS_XT1_TIMEOUT 50000
75 
76 //*****************************************************************************
77 //
78 //Desired Timeout for XT2 initialization
79 //
80 //*****************************************************************************
81 #define CS_XT2_TIMEOUT 0
82 
83 //*****************************************************************************
84 //
85 //XT1 Crystal Frequency being used
86 //
87 //*****************************************************************************
88 #define CS_XT1_CRYSTAL_FREQUENCY 32768
89 
90 //*****************************************************************************
91 //
92 //Variable to store returned STATUS_SUCCESS or STATUS_FAIL
93 //
94 //*****************************************************************************
95 uint8_t returnValue = 0;
96 
97 //*****************************************************************************
98 //
99 //Variable to store current clock values
100 //
101 //*****************************************************************************
102 uint32_t clockValue;
103 
104 //*****************************************************************************
105 //
106 //Variable to store status of Oscillator fault flags
107 //
108 //*****************************************************************************
109 uint16_t status;
110 
111 void main (void)
112 {
113  //Stop WDT
114  WDT_A_hold(WDT_A_BASE);
115 
116  //Set P1.1 to output ACLK
117  GPIO_setAsPeripheralModuleFunctionOutputPin(
118  GPIO_PORT_P1,
119  GPIO_PIN1,
120  GPIO_SECONDARY_MODULE_FUNCTION
121  );
122 
123  //Set P1.0 to output SMCLK
124  GPIO_setAsPeripheralModuleFunctionOutputPin(
125  GPIO_PORT_P1,
126  GPIO_PIN0,
127  GPIO_SECONDARY_MODULE_FUNCTION
128  );
129 
130  //Port select XT1
131  GPIO_setAsPeripheralModuleFunctionInputPin(
132  GPIO_PORT_P2,
133  GPIO_PIN6 + GPIO_PIN7,
134  GPIO_SECONDARY_MODULE_FUNCTION
135  );
136 
137  /*
138  * Disable the GPIO power-on default high-impedance mode to activate
139  * previously configured port settings
140  */
141  PMM_unlockLPM5();
142 
143  //Initializes the XT1 and XT2 crystal frequencies being used
144  CS_setExternalClockSource(
146  );
147 
148  //Initialize XT1. Returns STATUS_SUCCESS if initializes successfully
149  returnValue = CS_turnOnXT1LFWithTimeout(
150  CS_XT1_DRIVE_0,
152  );
153 
154  //Select XT1 as ACLK source
155  CS_initClockSignal(
156  CS_ACLK,
157  CS_XT1CLK_SELECT,
158  CS_CLOCK_DIVIDER_1
159  );
160 
161  //clear all OSC fault flag
162  CS_clearAllOscFlagsWithTimeout(1000);
163 
164  //Enable oscillator fault interrupt
165  SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
166 
167  // Enable global interrupt
168  __bis_SR_register(GIE);
169 
170  //Verify if the Clock settings are as expected
171  clockValue = CS_getMCLK();
172  clockValue = CS_getACLK();
173  clockValue = CS_getSMCLK();
174 
175  //Loop in place
176  while (1) ;
177 }
178 
179 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
180 #pragma vector=UNMI_VECTOR
181 __interrupt
182 #elif defined(__GNUC__)
183 __attribute__((interrupt(UNMI_VECTOR)))
184 #endif
185 void NMI_ISR(void)
186 {
187  do {
188  // If it still can't clear the oscillator fault flags after the timeout,
189  // trap and wait here.
190  status = CS_clearAllOscFlagsWithTimeout(1000);
191  } while(status != 0);
192 }
void NMI_ISR(void)
uint16_t status
#define CS_XT1_TIMEOUT
void main(void)
#define CS_XT1_CRYSTAL_FREQUENCY
uint8_t returnValue
uint32_t clockValue